<script setup>
import { ref, toRefs, reactive, onBeforeMount } from 'vue'
import CreateOrEdit from './CreateOrEdit.vue'
import { getCronJobDetailHandler as getDetail } from '../../api/cronjob.js';
import { useRoute } from 'vue-router' 
import { useItem } from '../../store/index.js'

const route = useRoute()
const useItemer = useItem()
let showEdit = ref(false)
const data = reactive({
  cronJobItem: {}
})
// 获取当前编辑的资源配置
onBeforeMount(async () => {
  const requestQuery = route.query // 获取请求参数
  await getDetail(requestQuery).then((res) => {
    useItemer.item.metadata = JSON.parse(JSON.stringify(res.data.data.item.metadata))// 赋值给pinia
    useItemer.item.spec = JSON.parse(JSON.stringify(res.data.data.item.spec.jobTemplate.spec))
    data.cronJobItem = JSON.parse(JSON.stringify(res.data.data.item))
    showEdit.value = true
    console.log('获取资源配置',data.cronJobItem)
  })
})
const { cronJobItem } = toRefs(data)
</script>

<template>
  <!-- <CreateOrEdit method="Update" resource-type="CronJob" v-if="showEdit" :cron-job-item="cronJobItem"></CreateOrEdit> -->
  <CreateOrEdit :method="route.query.method" v-if="showEdit" resource-type="CronJob" :cron-job-item="cronJobItem"></CreateOrEdit>
</template>

<style scoped>
</style>
